package com.ruoyi.huanghefd.utils;

import com.ruoyi.huanghefd.mapper.MakesheetMapper;
import com.ruoyi.huanghefd.mapper.WorksheetMapper;
import com.ruoyi.huanghefd.service.impl.MakesheetServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author gnplum
 * @Date 2023/11/11 18:20
 * @PackageName:com.ruoyi.huanghefd.utils
 * @ClassName: pubCommon
 * @Description: 通用类
 * @Version 1.0
 */
public class pubCommon {
    private static final Logger log = LoggerFactory.getLogger(pubCommon.class);


    @Resource
    WorksheetMapper worksheetMapper;
    @Resource
    MakesheetMapper makesheetMapper;

    /*
     * @Author gnplum
     * @Description //获取票编号
     * @Date 16:18 2023/11/6
     * @param Type 票号前缀 pjlx票据类型
     * @return
     * @return null
     **/
    public String getGenerateOrder(String Type,String pjlx) {

        log.info("获取票编号=" + Type +","+ pjlx);
        String strWsCode="";
        int order = 0;
        try {
            switch (pjlx) {
                case "ws"://工作票
                    log.info("工作票");
                    order = worksheetMapper.getWsCodeNum(Type);
                    break;
                case "ms"://操作票
                    log.info("操作票");
                    order = makesheetMapper.getMsCodeNum(Type);
                    break;
                default:
                    break;
            }
            log.info("order="+order);
            //DQ1202311110001
            strWsCode = Type + new SimpleDateFormat("yyyyMMdd").format(new Date()) + String.format("%03d", order);

            log.info("strWsCode="+strWsCode);

        } catch (Exception e) {
            strWsCode="";
            //e.printStackTrace();
            //throw  e;
            //log.error(e.getCause()+e.getMessage());
        }
        return  strWsCode;
    }
}
